<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>考试场次管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="__PUBLIC__/BeginnerAdmin/plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="__PUBLIC__/BeginnerAdmin/css/global.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/BeginnerAdmin/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="__PUBLIC__/BeginnerAdmin/css/table.css" />
</head>
<body>
<form>
    <div class="admin-main">

        <blockquote class="layui-elem-quote">
            <a href="javascript:;" class="layui-btn" id="add"onclick="NewPaperUI();">
                <i class="layui-icon">&#xe608;</i> 添加考试
            </a>
            <div class="layui-inline">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="text" name="so" lay-verify="so" autocomplete="off" class="layui-input" placeholder="请输入要搜索的内容">
                </div>
                <a href="javascript:;" class="layui-btn" id="search">
                    <i class="layui-icon">&#xe615;</i> 搜索
                </a>
        </blockquote>
        <fieldset class="layui-elem-field">
            <legend>考试管理</legend>
            <div class="layui-field-box layui-form">
                <table class="layui-table admin-table" lay-size="sm">
                    <thead>
                    <tr>
                        <th style="width: 60px;">考试编号</th>
                        <th>试卷标题</th>
                        <th>开始时间</th>
                        <th>结束时间</th>
                        <th>做题时长</th>
                        <th>单位</th>
                        <th>发起人</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="content">
                    <foreach name="ret" item="v" key="k">
                        <tr>
                            <th><{$v.id}></th>
                            <th><php>if(mb_strlen($v['examtitle'],'utf-8')>16){echo mb_substr($v['examtitle'],0,16,'utf-8').'...';}else{echo $v['examtitle'];}</php></th>
                            <td><if condition="$v.starttime neq 0"><{$v.starttime|date="Y-m-d H:i:s",###}><else />不限制</if></td>
                            <td><if condition="$v.finishtime neq 0"><{$v.finishtime|date="Y-m-d H:i:s",###}><else />不限制</if></td>
                            <td><php>echo $v['duration']/60;</php>分钟</td>
                            <td><if condition="$v.unit eq 1">个人<elseif condition="$v.unit eq 2" />年级<elseif condition="$v.unit eq 3" />全部<else />未知</if></td>
                            <td><{$v.name}></td>
                            <td style="width: 130px;">
                                <div class="layui-btn-group">
                                    <a class="layui-btn layui-btn-sm" title="编辑考试相关的信息" onclick="edit('<{$v.id}>','<{$v.unit}>');">
                                        <i class="layui-icon">&#xe642;</i>
                                    </a>
                                    <!--TestQuestions-->
                                    <a class="layui-btn layui-btn-sm" title="编辑考试题" onclick="newlibtab('<{:U('TestQuestions/Manage',array('assignmentid'=>$v['id']))}>','试卷编辑-<{$v.id}>');">
                                        <i class="layui-icon">&#xe621;</i>
                                    </a>
                                    <a class="layui-btn layui-btn-sm" title="批阅试卷" onclick="newlibtab('<{:U('ExamRead/Manage',array('assignmentid'=>$v['id']))}>','试卷批阅-<{$v.id}>');">
                                        <i class="layui-icon">&#xe6b2;</i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
            </div>

            <div class="layui-inline" style="Float:right;display:inline;" align="right">
                <div class="layui-input-inline" style="width: 63px;">
                    <input type="number" id="page" name="page" style="height:30px;width: 60px;" autocomplete="off" class="layui-input" value="<{$page}>">
                </div>
                <a class="layui-btn layui-btn-small" href="javascript:;" onclick="page();">
                    <i class="layui-icon">&#xe609;</i>
                </a>
            </div>


            <div id="pagediv" style="Float:right;" class="layui-btn-group" align="right">
                <a class="layui-btn layui-btn-small layui-btn-primary">第<{$page}>页,总<{$count}>页</a>
                <a class="layui-btn layui-btn-small" href="<{:U('Paper/Manage',array(page=>$page-1))}>">
                    <i class="layui-icon">&#xe603;</i>
                    <a class="layui-btn layui-btn-small" href="<{:U('Paper/Manage',array(page=>$page+1))}>">
                        <i class="layui-icon">&#xe602;</i>
                    </a>
            </div>
        </fieldset>
        <div class="admin-table-page">
            <div id="paged" class="page">

            </div>
        </div>
    </div>
</form>
<script type="text/javascript" src="__PUBLIC__/BeginnerAdmin/plugins/layui/layui.js"></script>
<script src="__PUBLIC__/AmazeUI/assets/js/jquery-1.8.0.min.js"></script>

<script>
    layui.use(['layer'], function() {
        var $ = layui.jquery, layer = layui.layer,tab = layui.tab;
    });

    function settime() {
        location.reload(true);
    }

    function NewPaperUI() {
        layer.open({
            title: '添加考试',
            maxmin: false,
            type: 2,
            id:1,
            content: 'Admin_Paper_NewPaperUI.html',
            area: ['750px', '500px'],
            end:function (index, layero) {
                settime();
            }
        });
    }

    function edit(id,unit) {
        layer.open({
            type: 1,
            area: ['500px', '120px'],
            content: '<div align="center" style="margin-top: 4%">' +
            '<a class="layui-btn" href="javascript:gotowindow(\'EditPaper\',\''+id+'\');">修改考试场次</a>' +
            '<a class="layui-btn" href="javascript:gotowindow(\'NewPaperGradeAndStudent\',\''+id+'\',\''+unit+'\');">编辑考试单位</a>' +
            '<a class="layui-btn" href="javascript:gotowindow(\'Comment\',\''+id+'\');">编辑静态评语</a>' +
            '<a class="layui-btn" href="javascript:gotowindow(\'Delete\',\''+id+'\');"><i class="layui-icon">&#xe640;</i>删除</a>' +
            '</div>' //这里content是一个普通的String
            ,end:function (index, layero) {
                layer.load(2);
                location.reload(true);
            }
        });
    }
    
    function gotowindow(name,id,unit) {
        var content = '';
        var title   = '信息';
        var _is     = true;
        var _msg    =  '';
        if(name == 'EditPaper'){
            title   = '编辑考生信息';
            content = 'Admin_Paper_EditPaperUI.html?examassignmentid='+id;
        }else if (name == 'NewPaperGradeAndStudent'){
            if (unit == 1){
                title   = '编辑考试学生';
                content = 'Admin_Paper_NewPaperStudentUI.html?examassignmentid='+id;
            } else if(unit == 2){
                title   = '编辑考试年级组';
                content = 'Admin_Paper_NewPaperGradeUI.html?examassignmentid='+id;
            }else if(unit == 3){
                _msg = '该类型的做题单位不需要编辑';
                _is = false;
            }else {
                _is = false;
            }
        }else if(name == 'Comment'){
            title   = '考试评语设置';
            content = 'Admin_Paper_CommentUI.html?assignmentid='+id;
        }else if(name == 'Delete'){
            var del = true;
        }else{
            _is = false;
        }

        if(_is){
            if(!del){
                layer.open({
                    title: title,
                    maxmin: false,
                    type: 2,
                    id:1,
                    content: content,
                    area: ['750px', '500px']
                });
            }else{
                layer.open({
                    title: '删除考试场次',
                    maxmin: false,
                    type: 1,
                    id:1,
                    resize:false,
                    content: '<div align="center">确定删除该考试场次？</div>',
                    btn:['确定','取消'],
                    btn1:function (index,layero) {
                        $.post('Admin_Paper_DeletePaper.html',
                            {examassignmentid:id},
                            function (date) {
                                if(date.code == 200){
                                    layer.open({type: 3});
                                    layer.msg('删除成功！');
                                    setTimeout('settime()', 1500);//延时执行，让人看得更清楚
                                }else{
                                    layer.alert('删除失败！');
                                }
                            },'json');
                        layer.close(index);

                    },
                    btn2:function (index,layero) {
                    }
                });
            }
        } else {
            if(_msg == null || _msg == ''){
                layer.msg('选择出错');
            }else{
                layer.msg(_msg);
            }

        }

    }

    function newlibtab(url,titles) {
        parent.tab.tabAdd({
            href: url, //地址
            icon: '&#xe63c;',
            title:titles
        });
    }


    function page() {
        window.location.href="Admin_Paper_Manage.html?page="+$("#page").val();
    }



</script>
</body>
</html>